<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_Spot_Extend_Field extends ORM {

    public static function get_data($spot_id='')
    {
        $field = DB::select('chinesename','columnname')->from('spot_content')
            ->where('issystem','!=',1)
            ->and_where('isopen','=',1)
            ->order_by(DB::expr(" IFNULL(displayorder,99999) asc "))
            ->execute()->as_array();
        if(count($field)<1){
            return [];
        }
        foreach ($field as &$v) {
            $v['content'] = $spot_id?self::get_field_content($v['columnname'],$spot_id):'';
        }

        return $field;
    }

    public static function get_field_content($field,$spot_id)
    {
        return DB::select()->from('spot_extend_field')
            ->where('productid','=',$spot_id)
            ->execute()->get($field);
    }
}